package com.springboot.frame.oauth.server.controller;

import com.springboot.frame.oauth.server.dto.LoginDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;


/**
 * 登录控制器
 *
 * @author Louis
 * @date Jun 29, 2019
 */
@Controller
public class LoginController {


    /**
     * 自定义登录页
     *
     * @param model
     * @return
     */
    @GetMapping("/login")
    public String loginPage(Model model) {
        model.addAttribute("loginProcessUrl", "/login");
        return "login";
    }

    @ResponseBody
    @PostMapping("/logout")
    public String logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return "登出成功";
    }
}
